package ar.edu.unq.tpi.uis.tepe3.wicket.pages;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import ar.edu.unq.tpi.uis.tepe3.dominio.Access;
import ar.edu.unq.tpi.uis.tepe3.dominio.Folder;
import ar.edu.unq.tpi.uis.tepe3.wicket.AbstractListPage;
import ar.edu.unq.tpi.uis.tepe3.wicket.panels.AccessListViewActionsPanel;
import ar.edu.unq.tpi.uis.tepe3.wicket.panels.DefaultAccessMenuPanel;
import ar.edu.unq.tpi.uis.tepe3.wicket.panels.DefaultListViewActionsPanel;

/**
 * @author gpilla <gpilla@unq.edu.ar>
 *
 */
public class AccessListPage extends AbstractListPage{

	/**
	 * @param aModel
	 */
	public AccessListPage(IModel aModel) {
		super("Listado de Accesos para una carpeta");
		this.setModel(aModel);
	
		ListView listView = new ListView("listview", getListViewDataSource()) {
            protected void populateItem(ListItem item) {
                Access anAccess = (Access) item.getModelObject();
                item.add(new Label("who", anAccess.getWho().toString()));
                item.add(new Label("how", anAccess.getHow().toString()));
                item.add(new AccessListViewActionsPanel("actions",item.getModel(), getModel()));
            }
		};
		
		add(listView);
		
	}


	private IModel getListViewDataSource() {
		return new CompoundPropertyModel(((Folder) getModelObject()).getAccesses());
	}


	@Override
	public void deleteAction(IModel model) {
		((Folder) getModelObject()).removeAccess((Access) model.getObject());
	}

	@Override
	protected void addLeftMenu() {
		add(new DefaultAccessMenuPanel("leftMenu", getModel()));
	}
	
}
